const imgpath1 = "http://pic-img.shike8888.com/";

export function completeImageUrl(arr,q,w){
    if (!arr){
        return null;
    }
    if (!q && !w){
        if (arr.startsWith('http://') || arr.startsWith('https://')){
            return arr;
        } else {
            return imgpath1 + arr;
        }
    }
    let a;
    q=60;
    w=400;
    if(arr.startsWith('http://') || arr.startsWith('https://')){

        if(arr.indexOf("image-user")>0 ||arr.indexOf("image-cdn")>0 ||arr.indexOf("oss-cn-hangzhou")>0 ){
            if(arr.indexOf("?x-oss-process=image")>0){
                return arr;
            }
            return arr+"?x-oss-process=image/resize,w_"+w+",p_"+q;
        }
        const sufix = q > 0 ? "_350x350q" + q + '.jpg' : "_350x350.jpg";
        const patt1 = new RegExp(".jpg_");
        const patt2 = new RegExp(".png_");
        const patt3 = new RegExp(".SS2_");

        if (patt1.test(arr)||patt2.test(arr)) {

            a = arr.split(".");
            return arr.replace(a[a.length-2]+'.'+a[a.length-1],'jpg'+sufix);
        }
        if(patt3.test(arr)){

            a = arr.split(".");
            return arr.replace(a[a.length-2]+'.'+a[a.length-1],'SS2'+sufix);
        }else{
            return arr.replace(".jpg", '.jpg'+sufix );
        }
    }else {
        return imgpath1 + arr + "?imageView2/2/w/" + w + "/q/" + q;
    }
}

export function replaceNameByStr(string,start,length,str){

    var preStr = string.substring(0,start);
    var mStr = "";
    for (var i = 0; i < length; i++) {
        mStr += str;
    }
    var lStr = string.charAt(string.length-1);
    return preStr+mStr+lStr;
}
